package com.apollographql.apollo.api.internal.json;

import com.apollographql.apollo.api.internal.json.JsonReader;
import java.io.EOFException;
import java.io.IOException;
import com.kt.Metadata;
import com.kt.Unit;
import com.kt.jvm.internal.DefaultConstructorMarker;
import com.kt.jvm.internal.Intrinsics;
import okio.Buffer;
import okio.BufferedSource;
import okio.ByteString;

@Metadata(bv = {1, 0, 3}, d1 = {"\u0000p\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\b\n\u0002\u0010\u0015\n\u0000\n\u0002\u0010\u0011\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\t\n\u0002\b\u0007\n\u0002\u0010\u0002\n\u0002\b\b\n\u0002\u0010\f\n\u0002\b\u0002\n\u0002\u0010\u0006\n\u0002\b\n\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\r\n\u0002\u0018\u0002\n\u0002\b\u0003\u0018\u0000 L2\u00020\u0001:\u0001LB\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\b\u0010\u001e\u001a\u00020\u0001H\u0016J\b\u0010\u001f\u001a\u00020\u0001H\u0016J\b\u0010 \u001a\u00020!H\u0002J\b\u0010\"\u001a\u00020!H\u0016J\b\u0010#\u001a\u00020\u0017H\u0002J\b\u0010$\u001a\u00020\u0001H\u0016J\b\u0010%\u001a\u00020\u0001H\u0016J\b\u0010&\u001a\u00020\u0014H\u0016J\t\u0010'\u001a\u00020\bH\u0002J\u0010\u0010(\u001a\u00020\b2\u0006\u0010)\u001a\u00020*H\u0002J\b\u0010+\u001a\u00020\bH\u0016J\b\u0010,\u001a\u00020-H\u0016J\b\u0010.\u001a\u00020\u0017H\u0016J\b\u0010/\u001a\u00020\u0019H\u0016J\b\u00100\u001a\u00020\u0014H\u0016J\u0010\u00101\u001a\u00020\u00172\u0006\u00102\u001a\u00020\bH\u0002J\u0015\u00103\u001a\u0004\u0018\u0001H4\"\u0004\b\u0000\u00104H\u0016¢\u0006\u0002\u00105J\u0010\u00106\u001a\u00020\u00142\u0006\u00107\u001a\u000208H\u0002J\n\u00109\u001a\u0004\u0018\u00010\u0014H\u0016J\b\u0010:\u001a\u00020\u0014H\u0002J\b\u0010;\u001a\u00020<H\u0016J\b\u0010=\u001a\u00020\u0017H\u0002J\b\u0010>\u001a\u00020\u0017H\u0002J\b\u0010?\u001a\u00020!H\u0016J\u0010\u0010@\u001a\u00020!2\u0006\u0010A\u001a\u00020\u0017H\u0002J\b\u0010B\u001a\u00020*H\u0002J\u0010\u0010C\u001a\u00020!2\u0006\u00107\u001a\u000208H\u0002J\u0010\u0010D\u001a\u00020\b2\u0006\u0010E\u001a\u00020\u0014H\u0002J\b\u0010F\u001a\u00020!H\u0002J\b\u0010G\u001a\u00020!H\u0002J\b\u0010H\u001a\u00020!H\u0016J\u0010\u0010I\u001a\u00020J2\u0006\u0010K\u001a\u00020\u0014H\u0002R\u000e\u0010\u0005\u001a\u00020\u0006X\u0004¢\u0006\u0002\n\u0000R\u001a\u0010\u0007\u001a\u00020\bX\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\t\u0010\n\"\u0004\b\u000b\u0010\fR\u001a\u0010\r\u001a\u00020\bX\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u000e\u0010\n\"\u0004\b\u000f\u0010\fR\u000e\u0010\u0010\u001a\u00020\u0011X\u0004¢\u0006\u0002\n\u0000R\u0018\u0010\u0012\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u00140\u0013X\u0004¢\u0006\u0004\n\u0002\u0010\u0015R\u000e\u0010\u0016\u001a\u00020\u0017X\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0018\u001a\u00020\u0019X\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u001a\u001a\u00020\u0017X\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u001b\u001a\u0004\u0018\u00010\u0014X\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u001c\u001a\u00020\u0011X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u001d\u001a\u00020\u0017X\u000e¢\u0006\u0002\n\u0000¨\u0006M"}, d2 = {"Lcom/apollographql/apollo/api/internal/json/BufferedSourceJsonReader;", "Lcom/apollographql/apollo/api/internal/json/JsonReader;", "source", "Lokio/BufferedSource;", "(Lokio/BufferedSource;)V", "buffer", "Lokio/Buffer;", "failOnUnknown", "", "getFailOnUnknown", "()Z", "setFailOnUnknown", "(Z)V", "lenient", "getLenient", "setLenient", "pathIndices", "", "pathNames", "", "", "[Ljava/lang/String;", "peeked", "", "peekedLong", "", "peekedNumberLength", "peekedString", "stack", "stackSize", "beginArray", "beginObject", "checkLenient", "", "close", "doPeek", "endArray", "endObject", "getPath", "hasNext", "isLiteral", "c", "", "nextBoolean", "nextDouble", "", "nextInt", "nextLong", "nextName", "nextNonWhitespace", "throwOnEof", "nextNull", "T", "()Ljava/lang/Object;", "nextQuotedValue", "runTerminator", "Lokio/ByteString;", "nextString", "nextUnquotedValue", "peek", "Lcom/apollographql/apollo/api/internal/json/JsonReader$Token;", "peekKeyword", "peekNumber", "promoteNameToValue", "push", "newTop", "readEscapeCharacter", "skipQuotedValue", "skipTo", "toFind", "skipToEndOfLine", "skipUnquotedValue", "skipValue", "syntaxError", "Lcom/apollographql/apollo/api/internal/json/JsonEncodingException;", "message", "Companion", "apollo-api"}, k = 1, mv = {1, 4, 0})
/* compiled from: BufferedSourceJsonReader.kt */
public final class BufferedSourceJsonReader implements JsonReader {
    public static final Companion Companion = new Companion(null);
    private static final ByteString DOUBLE_QUOTE_OR_SLASH = ByteString.encodeUtf8("\"\\");
    private static final ByteString LINEFEED_OR_CARRIAGE_RETURN = ByteString.encodeUtf8("\n\r");
    private static final long MIN_INCOMPLETE_INTEGER = -922337203685477580L;
    private static final int NUMBER_CHAR_DECIMAL = 3;
    private static final int NUMBER_CHAR_DIGIT = 2;
    private static final int NUMBER_CHAR_EXP_DIGIT = 7;
    private static final int NUMBER_CHAR_EXP_E = 5;
    private static final int NUMBER_CHAR_EXP_SIGN = 6;
    private static final int NUMBER_CHAR_FRACTION_DIGIT = 4;
    private static final int NUMBER_CHAR_NONE = 0;
    private static final int NUMBER_CHAR_SIGN = 1;
    private static final int PEEKED_BEGIN_ARRAY = 3;
    private static final int PEEKED_BEGIN_OBJECT = 1;
    private static final int PEEKED_BUFFERED = 11;
    private static final int PEEKED_DOUBLE_QUOTED = 9;
    private static final int PEEKED_DOUBLE_QUOTED_NAME = 13;
    private static final int PEEKED_END_ARRAY = 4;
    private static final int PEEKED_END_OBJECT = 2;
    private static final int PEEKED_EOF = 17;
    private static final int PEEKED_FALSE = 6;
    private static final int PEEKED_LONG = 15;
    private static final int PEEKED_NONE = 0;
    private static final int PEEKED_NULL = 7;
    private static final int PEEKED_NUMBER = 16;
    private static final int PEEKED_SINGLE_QUOTED = 8;
    private static final int PEEKED_SINGLE_QUOTED_NAME = 12;
    private static final int PEEKED_TRUE = 5;
    private static final int PEEKED_UNQUOTED = 10;
    private static final int PEEKED_UNQUOTED_NAME = 14;
    private static final ByteString SINGLE_QUOTE_OR_SLASH = ByteString.encodeUtf8("'\\");
    private static final ByteString UNQUOTED_STRING_TERMINALS = ByteString.encodeUtf8("{}[]:, \n\t\r/\\;#=");
    private final Buffer buffer;
    private boolean failOnUnknown;
    private boolean lenient;
    private final int[] pathIndices = new int[32];
    private final String[] pathNames = new String[32];
    private int peeked;
    private long peekedLong;
    private int peekedNumberLength;
    private String peekedString;
    private final BufferedSource source;
    private final int[] stack;
    private int stackSize = 1;

    public BufferedSourceJsonReader(BufferedSource source2) {
        Intrinsics.checkParameterIsNotNull(source2, "source");
        this.source = source2;
        this.buffer = source2.getBuffer();
        int[] $this$apply = new int[32];
        $this$apply[0] = 6;
        Unit unit = Unit.INSTANCE;
        this.stack = $this$apply;
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public boolean getLenient() {
        return this.lenient;
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public void setLenient(boolean z) {
        this.lenient = z;
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public boolean getFailOnUnknown() {
        return this.failOnUnknown;
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public void setFailOnUnknown(boolean z) {
        this.failOnUnknown = z;
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public JsonReader beginArray() throws IOException {
        BufferedSourceJsonReader $this$apply = this;
        Integer valueOf = Integer.valueOf($this$apply.peeked);
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        if ((valueOf != null ? valueOf.intValue() : $this$apply.doPeek()) == 3) {
            $this$apply.push(1);
            $this$apply.pathIndices[$this$apply.stackSize - 1] = 0;
            $this$apply.peeked = 0;
            return this;
        }
        throw new JsonDataException("Expected BEGIN_ARRAY but was " + $this$apply.peek() + " at path " + $this$apply.getPath());
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public JsonReader endArray() throws IOException {
        BufferedSourceJsonReader $this$apply = this;
        Integer valueOf = Integer.valueOf($this$apply.peeked);
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        if ((valueOf != null ? valueOf.intValue() : $this$apply.doPeek()) == 4) {
            int i = $this$apply.stackSize - 1;
            $this$apply.stackSize = i;
            int[] iArr = $this$apply.pathIndices;
            int i2 = i - 1;
            iArr[i2] = iArr[i2] + 1;
            $this$apply.peeked = 0;
            return this;
        }
        throw new JsonDataException("Expected END_ARRAY but was " + $this$apply.peek() + " at path " + $this$apply.getPath());
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public JsonReader beginObject() throws IOException {
        BufferedSourceJsonReader $this$apply = this;
        Integer valueOf = Integer.valueOf($this$apply.peeked);
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        if ((valueOf != null ? valueOf.intValue() : $this$apply.doPeek()) == 1) {
            $this$apply.push(3);
            $this$apply.peeked = 0;
            return this;
        }
        throw new JsonDataException("Expected BEGIN_OBJECT but was " + $this$apply.peek() + " at path " + $this$apply.getPath());
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public JsonReader endObject() throws IOException {
        BufferedSourceJsonReader $this$apply = this;
        Integer valueOf = Integer.valueOf($this$apply.peeked);
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        if ((valueOf != null ? valueOf.intValue() : $this$apply.doPeek()) == 2) {
            int i = $this$apply.stackSize - 1;
            $this$apply.stackSize = i;
            $this$apply.pathNames[i] = null;
            int[] iArr = $this$apply.pathIndices;
            int i2 = i - 1;
            iArr[i2] = iArr[i2] + 1;
            $this$apply.peeked = 0;
            return this;
        }
        throw new JsonDataException("Expected END_OBJECT but was " + $this$apply.peek() + " at path " + $this$apply.getPath());
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public boolean hasNext() throws IOException {
        Integer valueOf = Integer.valueOf(this.peeked);
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        int p = valueOf != null ? valueOf.intValue() : doPeek();
        if (p == 2 || p == 4) {
            return false;
        }
        return true;
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public Token peek() throws IOException {
        Integer valueOf = Integer.valueOf(this.peeked);
        if (valueOf.intValue() == 0) {
            valueOf = null;
        }
        switch (valueOf != null ? valueOf.intValue() : doPeek()) {
            case 1:
                return Token.BEGIN_OBJECT;
            case 2:
                return Token.END_OBJECT;
            case 3:
                return Token.BEGIN_ARRAY;
            case 4:
                return Token.END_ARRAY;
            case 5:
            case 6:
                return Token.BOOLEAN;
            case 7:
                return Token.NULL;
            case 8:
            case 9:
            case 10:
            case 11:
                return Token.STRING;
            case 12:
            case 13:
            case 14:
                return Token.NAME;
            case 15:
                return Token.LONG;
            case 16:
                return Token.NUMBER;
            case 17:
                return Token.END_DOCUMENT;
            default:
                throw new AssertionError();
        }
    }

    private final int doPeek() throws IOException {
        int[] iArr = this.stack;
        int i = this.stackSize;
        int peekStack = iArr[i - 1];
        boolean z = false;
        switch (peekStack) {
            case 1:
                iArr[i - 1] = 2;
                break;
            case 2:
                int c = nextNonWhitespace(true);
                this.buffer.readByte();
                char c2 = (char) c;
                if (c2 != ',') {
                    if (c2 == ';') {
                        checkLenient();
                        break;
                    } else if (c2 == ']') {
                        this.peeked = 4;
                        return 4;
                    } else {
                        throw syntaxError("Unterminated array");
                    }
                }
                break;
            case 3:
            case 5:
                iArr[i - 1] = 4;
                if (peekStack == 5) {
                    int c3 = nextNonWhitespace(true);
                    this.buffer.readByte();
                    char c4 = (char) c3;
                    if (c4 != ',') {
                        if (c4 == ';') {
                            checkLenient();
                        } else if (c4 == '}') {
                            this.peeked = 2;
                            return 2;
                        } else {
                            throw syntaxError("Unterminated object");
                        }
                    }
                }
                int c5 = nextNonWhitespace(true);
                char c6 = (char) c5;
                if (c6 == '\"') {
                    this.buffer.readByte();
                    this.peeked = 13;
                    return 13;
                } else if (c6 == '\'') {
                    this.buffer.readByte();
                    checkLenient();
                    this.peeked = 12;
                    return 12;
                } else if (c6 != '}') {
                    checkLenient();
                    if (isLiteral((char) c5)) {
                        this.peeked = 14;
                        return 14;
                    }
                    throw syntaxError("Expected name");
                } else if (peekStack != 5) {
                    this.buffer.readByte();
                    this.peeked = 2;
                    return 2;
                } else {
                    throw syntaxError("Expected name");
                }
            case 4:
                iArr[i - 1] = 5;
                int c7 = nextNonWhitespace(true);
                this.buffer.readByte();
                char c8 = (char) c7;
                if (c8 != ':') {
                    if (c8 == '=') {
                        checkLenient();
                        if (this.source.request(1) && this.buffer.getByte(0) == ((byte) 62)) {
                            this.buffer.readByte();
                            break;
                        }
                    } else {
                        throw syntaxError("Expected ':'");
                    }
                }
                break;
            case 6:
                iArr[i - 1] = 7;
                break;
            case 7:
                if (nextNonWhitespace(false) != -1) {
                    checkLenient();
                    break;
                } else {
                    this.peeked = 17;
                    return 17;
                }
            default:
                if (peekStack != 8) {
                    z = true;
                }
                if (!z) {
                    throw new IllegalStateException("JsonReader is closed".toString());
                }
                break;
        }
        char nextNonWhitespace = (char) nextNonWhitespace(true);
        if (nextNonWhitespace == '\"') {
            this.buffer.readByte();
            this.peeked = 9;
            return 9;
        } else if (nextNonWhitespace == '\'') {
            checkLenient();
            this.buffer.readByte();
            this.peeked = 8;
            return 8;
        } else if (nextNonWhitespace == ',' || nextNonWhitespace == ';') {
            if (peekStack == 1 || peekStack == 2) {
                checkLenient();
                this.peeked = 7;
                return 7;
            }
            throw syntaxError("Unexpected value");
        } else if (nextNonWhitespace == '[') {
            this.buffer.readByte();
            this.peeked = 3;
            return 3;
        } else if (nextNonWhitespace != ']') {
            if (nextNonWhitespace != '{') {
                int result = peekKeyword();
                if (result != 0) {
                    return result;
                }
                int result2 = peekNumber();
                if (result2 != 0) {
                    return result2;
                }
                if (isLiteral((char) this.buffer.getByte(0))) {
                    checkLenient();
                    this.peeked = 10;
                    return 10;
                }
                throw syntaxError("Expected value");
            }
            this.buffer.readByte();
            this.peeked = 1;
            return 1;
        } else if (peekStack == 1) {
            this.buffer.readByte();
            this.peeked = 4;
            return 4;
        } else if (peekStack == 1 || peekStack == 2) {
            checkLenient();
            this.peeked = 7;
            return 7;
        } else {
            throw syntaxError("Unexpected value");
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:19:0x0040  */
    /* JADX WARNING: Removed duplicated region for block: B:30:0x006f  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private final int peekKeyword() throws IOException {
        /*
        // Method dump skipped, instructions count: 137
        */
        throw new UnsupportedOperationException("Method not decompiled: com.apollographql.apollo.api.internal.json.BufferedSourceJsonReader.peekKeyword():int");
    }

    private final int peekNumber() throws IOException {
        byte c = 0;
        long value = 0;
        boolean negative = false;
        boolean fitsInLong = true;
        int last = 0;
        int i = 0;
        while (true) {
            boolean z = false;
            if (!this.source.request(((long) i) + 1)) {
                break;
            }
            c = this.buffer.getByte((long) i);
            char c2 = (char) c;
            if (c2 != '+') {
                if (c2 == 'E' || c2 == 'e') {
                    if (last != 2 && last != 4) {
                        return 0;
                    }
                    last = 5;
                } else if (c2 != '-') {
                    if (c2 != '.') {
                        byte b = (byte) 48;
                        if (c >= b && c <= ((byte) 57)) {
                            if (last == 0 || last == 1) {
                                value = -((long) (c - b));
                                last = 2;
                            } else if (last != 2) {
                                if (last == 3) {
                                    last = 4;
                                } else if (last == 5 || last == 6) {
                                    last = 7;
                                }
                            } else if (value == 0) {
                                return 0;
                            } else {
                                long newValue = (((long) 10) * value) - ((long) (c - b));
                                if (((value > -922337203685477580L) && fitsInLong) || (value == -922337203685477580L && newValue < value)) {
                                    z = true;
                                }
                                fitsInLong = z;
                                value = newValue;
                            }
                        }
                    } else if (last != 2) {
                        return 0;
                    } else {
                        last = 3;
                    }
                } else if (last == 0) {
                    negative = true;
                    last = 1;
                } else if (last != 5) {
                    return 0;
                } else {
                    last = 6;
                }
            } else if (last != 5) {
                return 0;
            } else {
                last = 6;
            }
            i++;
        }
        if (isLiteral((char) c)) {
            return 0;
        }
        if (last == 2 && fitsInLong && (value != Long.MIN_VALUE || negative)) {
            this.peekedLong = negative ? value : -value;
            this.buffer.skip((long) i);
            this.peeked = 15;
            return 15;
        } else if (last != 2 && last != 4 && last != 7) {
            return 0;
        } else {
            this.peekedNumberLength = i;
            this.peeked = 16;
            return 16;
        }
    }

    private final boolean isLiteral(char c) throws IOException {
        if (c == '\t' || c == '\n' || c == '\r' || c == ' ') {
            return false;
        }
        if (c != '#') {
            if (c == ',') {
                return false;
            }
            if (!(c == '/' || c == '=')) {
                if (c == '{' || c == '}' || c == ':') {
                    return false;
                }
                if (c != ';') {
                    switch (c) {
                        case '[':
                        case ']':
                            return false;
                        case '\\':
                            break;
                        default:
                            return true;
                    }
                }
            }
        }
        checkLenient();
        return false;
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public String nextName() throws IOException {
        String result;
        Integer valueOf = Integer.valueOf(this.peeked);
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        switch (valueOf != null ? valueOf.intValue() : doPeek()) {
            case 12:
                result = nextQuotedValue(SINGLE_QUOTE_OR_SLASH);
                break;
            case 13:
                result = nextQuotedValue(DOUBLE_QUOTE_OR_SLASH);
                break;
            case 14:
                result = nextUnquotedValue();
                break;
            default:
                throw new JsonDataException("Expected a name but was " + peek() + " at path " + getPath());
        }
        this.peeked = 0;
        this.pathNames[this.stackSize - 1] = result;
        return result;
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public String nextString() throws IOException {
        Integer valueOf = Integer.valueOf(this.peeked);
        String result = null;
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        int intValue = valueOf != null ? valueOf.intValue() : doPeek();
        if (intValue == 15) {
            result = String.valueOf(this.peekedLong);
        } else if (intValue != 16) {
            switch (intValue) {
                case 8:
                    result = nextQuotedValue(SINGLE_QUOTE_OR_SLASH);
                    break;
                case 9:
                    result = nextQuotedValue(DOUBLE_QUOTE_OR_SLASH);
                    break;
                case 10:
                    result = nextUnquotedValue();
                    break;
                case 11:
                    String str = this.peekedString;
                    if (str != null) {
                        this.peekedString = null;
                        result = str;
                        break;
                    }
                    break;
                default:
                    throw new JsonDataException("Expected a string but was " + peek() + " at path " + getPath());
            }
        } else {
            result = this.buffer.readUtf8((long) this.peekedNumberLength);
        }
        this.peeked = 0;
        int[] iArr = this.pathIndices;
        int i = this.stackSize - 1;
        iArr[i] = iArr[i] + 1;
        return result;
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public boolean nextBoolean() throws IOException {
        Integer valueOf = Integer.valueOf(this.peeked);
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        int intValue = valueOf != null ? valueOf.intValue() : doPeek();
        if (intValue == 5) {
            this.peeked = 0;
            int[] iArr = this.pathIndices;
            int i = this.stackSize - 1;
            iArr[i] = iArr[i] + 1;
            return true;
        } else if (intValue == 6) {
            this.peeked = 0;
            int[] iArr2 = this.pathIndices;
            int i2 = this.stackSize - 1;
            iArr2[i2] = iArr2[i2] + 1;
            return false;
        } else {
            throw new JsonDataException("Expected a boolean but was " + peek() + " at path " + getPath());
        }
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public <T> T nextNull() throws IOException {
        Integer valueOf = Integer.valueOf(this.peeked);
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        if ((valueOf != null ? valueOf.intValue() : doPeek()) == 7) {
            this.peeked = 0;
            int[] iArr = this.pathIndices;
            int i = this.stackSize - 1;
            iArr[i] = iArr[i] + 1;
            return null;
        }
        throw new JsonDataException("Expected null but was " + peek() + " at path " + getPath());
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public double nextDouble() throws IOException {
        Integer valueOf = Integer.valueOf(this.peeked);
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        int p = valueOf != null ? valueOf.intValue() : doPeek();
        if (p == 15) {
            this.peeked = 0;
            int[] iArr = this.pathIndices;
            int i = this.stackSize - 1;
            iArr[i] = iArr[i] + 1;
            return (double) this.peekedLong;
        }
        if (p == 16) {
            this.peekedString = this.buffer.readUtf8((long) this.peekedNumberLength);
        } else if (p == 9) {
            this.peekedString = nextQuotedValue(DOUBLE_QUOTE_OR_SLASH);
        } else if (p == 8) {
            this.peekedString = nextQuotedValue(SINGLE_QUOTE_OR_SLASH);
        } else if (p == 10) {
            this.peekedString = nextUnquotedValue();
        } else if (p != 11) {
            throw new JsonDataException("Expected a double but was " + peek() + " at path " + getPath());
        }
        this.peeked = 11;
        try {
            String str = this.peekedString;
            if (str == null) {
                Intrinsics.throwNpe();
            }
            double result = Double.parseDouble(str);
            if (getLenient() || (!Double.isNaN(result) && !Double.isInfinite(result))) {
                this.peekedString = null;
                this.peeked = 0;
                int[] iArr2 = this.pathIndices;
                int i2 = this.stackSize - 1;
                iArr2[i2] = iArr2[i2] + 1;
                return result;
            }
            throw new JsonEncodingException("JSON forbids NaN and infinities: " + result + " at path " + getPath());
        } catch (NumberFormatException e) {
            throw new JsonDataException("Expected a double but was " + this.peekedString + " at path " + getPath());
        }
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public long nextLong() throws IOException {
        Integer valueOf = Integer.valueOf(this.peeked);
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        int p = valueOf != null ? valueOf.intValue() : doPeek();
        if (p == 15) {
            this.peeked = 0;
            int[] iArr = this.pathIndices;
            int i = this.stackSize - 1;
            iArr[i] = iArr[i] + 1;
            return this.peekedLong;
        }
        if (p == 16) {
            this.peekedString = this.buffer.readUtf8((long) this.peekedNumberLength);
        } else if (p == 9 || p == 8) {
            String nextQuotedValue = nextQuotedValue(p == 9 ? DOUBLE_QUOTE_OR_SLASH : SINGLE_QUOTE_OR_SLASH);
            this.peekedString = nextQuotedValue;
            if (nextQuotedValue == null) {
                try {
                    Intrinsics.throwNpe();
                } catch (NumberFormatException e) {
                }
            }
            long result = Long.parseLong(nextQuotedValue);
            this.peeked = 0;
            int[] iArr2 = this.pathIndices;
            int i2 = this.stackSize - 1;
            iArr2[i2] = iArr2[i2] + 1;
            return result;
        } else if (p != 11) {
            throw new JsonDataException("Expected a long but was " + peek() + " at path " + getPath());
        }
        this.peeked = 11;
        try {
            String str = this.peekedString;
            if (str == null) {
                Intrinsics.throwNpe();
            }
            double asDouble = Double.parseDouble(str);
            long result2 = (long) asDouble;
            if (((double) result2) == asDouble) {
                this.peekedString = null;
                this.peeked = 0;
                int[] iArr3 = this.pathIndices;
                int i3 = this.stackSize - 1;
                iArr3[i3] = iArr3[i3] + 1;
                return result2;
            }
            throw new JsonDataException("Expected a long but was " + this.peekedString + " at path " + getPath());
        } catch (NumberFormatException e2) {
            throw new JsonDataException("Expected a long but was " + this.peekedString + " at path " + getPath());
        }
    }

    private final String nextQuotedValue(ByteString runTerminator) throws IOException {
        StringBuilder builder = null;
        while (true) {
            long index = this.source.indexOfElement(runTerminator);
            if (index == -1) {
                throw syntaxError("Unterminated string");
            } else if (this.buffer.getByte(index) == ((byte) 92)) {
                if (builder == null) {
                    builder = new StringBuilder();
                }
                builder.append(this.buffer.readUtf8(index));
                this.buffer.readByte();
                builder.append(readEscapeCharacter());
            } else if (builder == null) {
                String readUtf8 = this.buffer.readUtf8(index);
                this.buffer.readByte();
                return readUtf8;
            } else {
                builder.append(this.buffer.readUtf8(index));
                this.buffer.readByte();
                String sb = builder.toString();
                Intrinsics.checkExpressionValueIsNotNull(sb, "builder.toString()");
                return sb;
            }
        }
    }

    private final String nextUnquotedValue() throws IOException {
        long i = this.source.indexOfElement(UNQUOTED_STRING_TERMINALS);
        int i2 = (i > -1 ? 1 : (i == -1 ? 0 : -1));
        Buffer buffer2 = this.buffer;
        return i2 != 0 ? buffer2.readUtf8(i) : buffer2.readUtf8();
    }

    private final void skipQuotedValue(ByteString runTerminator) throws IOException {
        while (true) {
            long index = this.source.indexOfElement(runTerminator);
            if (index == -1) {
                throw syntaxError("Unterminated string");
            } else if (this.buffer.getByte(index) == ((byte) 92)) {
                this.buffer.skip(1 + index);
                readEscapeCharacter();
            } else {
                this.buffer.skip(1 + index);
                return;
            }
        }
    }

    private final void skipUnquotedValue() throws IOException {
        long i = this.source.indexOfElement(UNQUOTED_STRING_TERMINALS);
        Buffer buffer2 = this.buffer;
        buffer2.skip(i != -1 ? i : buffer2.size());
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public int nextInt() throws IOException {
        Integer valueOf = Integer.valueOf(this.peeked);
        if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
            valueOf = null;
        }
        int p = valueOf != null ? valueOf.intValue() : doPeek();
        if (p == 15) {
            long j = this.peekedLong;
            int result = (int) j;
            if (j == ((long) result)) {
                this.peeked = 0;
                int[] iArr = this.pathIndices;
                int i = this.stackSize - 1;
                iArr[i] = iArr[i] + 1;
                return result;
            }
            throw new JsonDataException("Expected an int but was " + this.peekedLong + " at path " + getPath());
        }
        if (p == 16) {
            this.peekedString = this.buffer.readUtf8((long) this.peekedNumberLength);
        } else if (p == 9 || p == 8) {
            String nextQuotedValue = nextQuotedValue(p == 9 ? DOUBLE_QUOTE_OR_SLASH : SINGLE_QUOTE_OR_SLASH);
            this.peekedString = nextQuotedValue;
            if (nextQuotedValue == null) {
                try {
                    Intrinsics.throwNpe();
                } catch (NumberFormatException e) {
                }
            }
            int result2 = Integer.parseInt(nextQuotedValue);
            this.peeked = 0;
            int[] iArr2 = this.pathIndices;
            int i2 = this.stackSize - 1;
            iArr2[i2] = iArr2[i2] + 1;
            return result2;
        } else if (p != 11) {
            throw new JsonDataException("Expected an int but was " + peek() + " at path " + getPath());
        }
        this.peeked = 11;
        try {
            String str = this.peekedString;
            if (str == null) {
                Intrinsics.throwNpe();
            }
            double asDouble = Double.parseDouble(str);
            int result3 = (int) asDouble;
            if (((double) result3) == asDouble) {
                this.peekedString = null;
                this.peeked = 0;
                int[] iArr3 = this.pathIndices;
                int i3 = this.stackSize - 1;
                iArr3[i3] = iArr3[i3] + 1;
                return result3;
            }
            throw new JsonDataException("Expected an int but was " + this.peekedString + " at path " + getPath());
        } catch (NumberFormatException e2) {
            throw new JsonDataException("Expected an int but was " + this.peekedString + " at path " + getPath());
        }
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        this.peeked = 0;
        this.stack[0] = 8;
        this.stackSize = 1;
        this.buffer.clear();
        this.source.close();
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public void skipValue() throws IOException {
        if (!getFailOnUnknown()) {
            int count = 0;
            do {
                Integer valueOf = Integer.valueOf(this.peeked);
                if ((valueOf.intValue() == 0 ? 1 : 0) != 0) {
                    valueOf = null;
                }
                switch (valueOf != null ? valueOf.intValue() : doPeek()) {
                    case 1:
                        push(3);
                        count++;
                        break;
                    case 2:
                        this.stackSize--;
                        count--;
                        break;
                    case 3:
                        push(1);
                        count++;
                        break;
                    case 4:
                        this.stackSize--;
                        count--;
                        break;
                    case 8:
                    case 12:
                        skipQuotedValue(SINGLE_QUOTE_OR_SLASH);
                        break;
                    case 9:
                    case 13:
                        skipQuotedValue(DOUBLE_QUOTE_OR_SLASH);
                        break;
                    case 10:
                    case 14:
                        skipUnquotedValue();
                        break;
                    case 16:
                        this.buffer.skip((long) this.peekedNumberLength);
                        break;
                }
                this.peeked = 0;
            } while (count != 0);
            int[] iArr = this.pathIndices;
            int i = this.stackSize;
            int i2 = i - 1;
            iArr[i2] = iArr[i2] + 1;
            this.pathNames[i - 1] = "null";
            return;
        }
        throw new JsonDataException("Cannot skip unexpected " + peek() + " at " + getPath());
    }

    private final void push(int newTop) {
        int i = this.stackSize;
        int[] iArr = this.stack;
        if (i != iArr.length) {
            this.stackSize = i + 1;
            iArr[i] = newTop;
            return;
        }
        throw new JsonDataException("Nesting too deep at " + getPath());
    }

    private final int nextNonWhitespace(boolean throwOnEof) throws IOException {
        int c = 0;
        while (this.source.request(((long) c) + 1)) {
            int p = c + 1;
            int c2 = this.buffer.getByte((long) c);
            if (c2 == 10 || c2 == 32 || c2 == 13 || c2 == 9) {
                c = p;
            } else {
                this.buffer.skip(((long) p) - 1);
                if (c2 == 47) {
                    if (!this.source.request(2)) {
                        return c2;
                    }
                    checkLenient();
                    char c3 = (char) this.buffer.getByte(1);
                    if (c3 == '*') {
                        this.buffer.readByte();
                        this.buffer.readByte();
                        if (skipTo("*/")) {
                            this.buffer.readByte();
                            this.buffer.readByte();
                            c = 0;
                        } else {
                            throw syntaxError("Unterminated comment");
                        }
                    } else if (c3 != '/') {
                        return c2;
                    } else {
                        this.buffer.readByte();
                        this.buffer.readByte();
                        skipToEndOfLine();
                        c = 0;
                    }
                } else if (c2 != 35) {
                    return c2;
                } else {
                    checkLenient();
                    skipToEndOfLine();
                    c = 0;
                }
            }
        }
        if (!throwOnEof) {
            return -1;
        }
        throw new EOFException("End of input");
    }

    private final void checkLenient() throws IOException {
        if (!getLenient()) {
            throw syntaxError("Use JsonReader.setLenient(true) to accept malformed JSON");
        }
    }

    private final void skipToEndOfLine() throws IOException {
        long index = this.source.indexOfElement(LINEFEED_OR_CARRIAGE_RETURN);
        Buffer buffer2 = this.buffer;
        buffer2.skip(index != -1 ? 1 + index : buffer2.size());
    }

    private final boolean skipTo(String toFind) throws IOException {
        while (true) {
            if (!this.source.request((long) toFind.length())) {
                return false;
            }
            int length = toFind.length();
            for (int c = 0; c < length; c++) {
                if (this.buffer.getByte((long) c) != ((byte) toFind.charAt(c))) {
                    this.buffer.readByte();
                }
            }
            return true;
        }
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public String getPath() {
        return JsonScope.INSTANCE.getPath(this.stackSize, this.stack, this.pathNames, this.pathIndices);
    }

    private final char readEscapeCharacter() throws IOException {
        int i;
        if (this.source.request(1)) {
            char escaped = (char) this.buffer.readByte();
            if (escaped == '\n' || escaped == '\"' || escaped == '\'' || escaped == '/' || escaped == '\\') {
                return escaped;
            }
            if (escaped == 'b') {
                return '\b';
            }
            if (escaped == 'f') {
                return '\f';
            }
            if (escaped == 'n') {
                return '\n';
            }
            if (escaped == 'r') {
                return '\r';
            }
            if (escaped == 't') {
                return '\t';
            }
            if (escaped != 'u') {
                if (getLenient()) {
                    return escaped;
                }
                throw syntaxError("Invalid escape sequence: \\" + escaped);
            } else if (this.source.request(4)) {
                char result = (char) 0;
                int end = 0 + 4;
                for (int i2 = 0; i2 < end; i2++) {
                    byte c = this.buffer.getByte((long) i2);
                    char result2 = (char) (result << 4);
                    byte b = (byte) 48;
                    if (c < b || c > ((byte) 57)) {
                        byte b2 = (byte) 97;
                        if (c < b2 || c > ((byte) 102)) {
                            byte b3 = (byte) 65;
                            if (c < b3 || c > ((byte) 70)) {
                                throw syntaxError("\\u" + this.buffer.readUtf8(4));
                            }
                            i = (c - b3) + 10;
                        } else {
                            i = (c - b2) + 10;
                        }
                    } else {
                        i = c - b;
                    }
                    result = (char) (i + result2);
                }
                this.buffer.skip(4);
                return result;
            } else {
                throw new EOFException("Unterminated escape sequence at path " + getPath());
            }
        } else {
            throw syntaxError("Unterminated escape sequence");
        }
    }

    private final JsonEncodingException syntaxError(String message) {
        return new JsonEncodingException(message + " at path " + getPath());
    }

    @Override // com.apollographql.apollo.api.internal.json.JsonReader
    public void promoteNameToValue() throws IOException {
        if (hasNext()) {
            this.peekedString = nextName();
            this.peeked = 11;
        }
    }

    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\"\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\t\n\u0000\n\u0002\u0010\b\n\u0002\b\u001c\b\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002R\u000e\u0010\u0003\u001a\u00020\u0004X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0004X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0007XT¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u000b\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\f\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\r\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u000e\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u000f\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u0010\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u0011\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u0012\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u0013\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u0014\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u0015\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u0016\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u0017\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u0018\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u0019\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u001a\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u001b\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u001c\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u001d\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u001e\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\u001f\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010 \u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010!\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010\"\u001a\u00020\tXT¢\u0006\u0002\n\u0000R\u000e\u0010#\u001a\u00020\u0004X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010$\u001a\u00020\u0004X\u0004¢\u0006\u0002\n\u0000¨\u0006%"}, d2 = {"Lcom/apollographql/apollo/api/internal/json/BufferedSourceJsonReader$Companion;", "", "()V", "DOUBLE_QUOTE_OR_SLASH", "Lokio/ByteString;", "LINEFEED_OR_CARRIAGE_RETURN", "MIN_INCOMPLETE_INTEGER", "", "NUMBER_CHAR_DECIMAL", "", "NUMBER_CHAR_DIGIT", "NUMBER_CHAR_EXP_DIGIT", "NUMBER_CHAR_EXP_E", "NUMBER_CHAR_EXP_SIGN", "NUMBER_CHAR_FRACTION_DIGIT", "NUMBER_CHAR_NONE", "NUMBER_CHAR_SIGN", "PEEKED_BEGIN_ARRAY", "PEEKED_BEGIN_OBJECT", "PEEKED_BUFFERED", "PEEKED_DOUBLE_QUOTED", "PEEKED_DOUBLE_QUOTED_NAME", "PEEKED_END_ARRAY", "PEEKED_END_OBJECT", "PEEKED_EOF", "PEEKED_FALSE", "PEEKED_LONG", "PEEKED_NONE", "PEEKED_NULL", "PEEKED_NUMBER", "PEEKED_SINGLE_QUOTED", "PEEKED_SINGLE_QUOTED_NAME", "PEEKED_TRUE", "PEEKED_UNQUOTED", "PEEKED_UNQUOTED_NAME", "SINGLE_QUOTE_OR_SLASH", "UNQUOTED_STRING_TERMINALS", "apollo-api"}, k = 1, mv = {1, 4, 0})
    /* compiled from: BufferedSourceJsonReader.kt */
    public static final class Companion {
        private Companion() {
        }

        public /* synthetic */ Companion(DefaultConstructorMarker $constructor_marker) {
            this();
        }
    }
}
